// packageOrder/components/OrderItem/OrderItem.js
import { moment, calendar } from '../../../utils/format/DateFormat';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    data: {
      type:Object,
      observer: function (newData, oldData) {
        newData.endTime = calendar(newData.endTime);
        this.setData({ data: newData });
      }
    },
    type: Number,
    userType: Number
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    trigger: function(event){
      let myEventOption = {
        bubbles: false,//事件是否冒泡
        composed: false,//事件是否可以穿越组件边界
        capturePhase: false //事件是否拥有捕获阶段
      }
      this.triggerEvent(event, {}, myEventOption);
    },
    /**我要选厂操作 */
    onSelectFactory:function(){
      this.trigger("selectfactory");
    },
    /**质量评价操作 */
    onQualityEvaluate:function(){
      if (this.properties.data.orderStatus == 2){
        this.trigger("qualityeval")
      }
    },
    /**支付评价操作 */
    onPayEvaluate:function(){
      const { orderStatus, subStatus } = this.properties.data;
      if (orderStatus == 4 || (orderStatus == 5 && subStatus == 6)) {
        this.trigger("payeval")
      }
    },
    /**保证金退还 */
    onBondBack:function(){
      if (this.properties.data.orderStatus == 3) {
        this.trigger("bondback")
      }
    },
    /**延期退保操作 */
    onDelayBack: function(){
      if (this.properties.data.orderStatus == 3) {
        this.trigger("delayback");
      }
    },
    /**延期退保后，保金退还 */
    onDelayBondBack:function(){
      if (this.properties.data.subStatus == 5) {
        this.trigger("delaybondback")
      }
    },
    /**订单出厂操作 */
    onOutFactory: function(){
      if (this.properties.data.orderStatus == 1) {
        this.trigger("outfactory")
      }
    },
    /**申请售后 */
    onAfterSale:function(){
      if (this.properties.data.orderStatus == 7) {
        this.trigger("aftersale")
      }
    },
    /**我要投诉 */
    onComplain:function(){
      this.trigger("complain")
    },
    /**发红包 */
    onEnvelopSpilt:function(){
      this.trigger("envelopspilt")
    },
    /**修改订单 */
    onUpdateOrder:function(){
      this.trigger("updateorder")
    },
    /**中标工厂 */
    onZbFactory: function(){
      this.trigger("zbfactory")
    },
    /**我要评论 */
    onEvaluate: function(){
      this.trigger("evaluate")
    },
    onItemTap:function(){
      this.trigger("itemtap")
    }
  }
})
